<template>
  <div class="multi-choice-q">
    <div class="content">
      <n-thing content-indented>
        <template #header>
          <n-row class="title">
            <div class="index" v-if="props.index">{{ props.index + '.' }}</div>
            <div v-if="props.onlyAnswer">
              <n-checkbox-group
                :value="formData.optionsSelect"
                v-if="props.showDetail"
              >
                <n-space vertical>
                  <n-checkbox
                    v-for="(option, index) in formData.options"
                    :key="index"
                    :value="option"
                    :label="option"
                  />
                </n-space>
              </n-checkbox-group>
              <n-space v-else>
                <n-text
                  v-for="select in optionsSelect"
                  :key="select.toString()"
                >
                  {{ select }} <n-divider vertical></n-divider>
                </n-text>
              </n-space>
            </div>
            <div v-if="formData.title && !props.onlyAnswer">
              <span v-show="formData.required === '必填'" style="color: red"
                >*</span
              >
              {{ formData.title }}
            </div>
          </n-row>
        </template>
        <template #description v-if="formData.remark && !props.onlyAnswer">
          <div class="remark">
            {{ '——' + formData.remark }}
          </div>
        </template>
        <div v-if="!props.onlyAnswer">
          <n-checkbox-group
            :value="formData.optionsSelect"
            v-if="props.showDetail"
          >
            <n-space vertical>
              <n-checkbox
                v-for="(option, index) in formData.options"
                :key="index"
                :value="option"
                :label="option"
              />
            </n-space>
          </n-checkbox-group>
          <n-space v-else>
            <n-text v-for="select in optionsSelect" :key="select.toString()">
              {{ select }} <n-divider vertical></n-divider>
            </n-text>
          </n-space>
        </div>
      </n-thing>
    </div>
  </div>
</template>

<script setup lang="ts">
import { CheckmarkDoneCircle as FlashIcon } from '@vicons/ionicons5';
import { ref, reactive } from 'vue';

const props = defineProps({
  index: {
    type: Number,
    default: 0,
  },
  title: {
    type: String,
    required: true,
  },
  required: {
    type: String,
    default: '非必填',
  },
  remark: {
    type: String,
    default: '',
  },
  options: {
    type: Array,
    default: [],
  },
  optionsSelect: {
    type: Array,
    default: [],
  },
  showDetail: {
    type: Boolean,
    defualt: false,
  },
  onlyAnswer: {
    type: Boolean,
    default: false,
  },
});

const formData: any = reactive({
  title: props.title,
  remark: props.remark,
  required: props.required,
  options: props.options,
  optionsSelect: props.optionsSelect,
});

const emit = defineEmits(['update:optionsSelect']);
const upO = (value: string) => {
  emit('update:optionsSelect', value);
};
const formRef = ref(null);
</script>

<style scoped lang="scss">
.multi-choice-q {
  .index {
    margin-right: 1vw;
  }
  .content {
    padding: 1vw;
  }
  .title {
    font-size: 1.25rem;
  }
  .remark {
    font-size: 1rem;
    color: #999;
  }
  .edit {
    padding: 0 5vw;
  }
}
</style>
